<template>
  <div>
    <!-- 头部 -->
    <market-header></market-header>
    <!-- 内容 -->
    <div class="container">
      <div class="input">
        <label>用户名</label>
        <rh-input v-model="username"
                  placeholder="请输入用户名"></rh-input>
      </div>
      <div class="input">
        <label>邮箱</label>
        <rh-input v-model="userMail"
                  placeholder="请输入邮箱"></rh-input>
      </div>
      <div class="input">
        <label>手机号</label>
        <rh-input v-model="userPhone"
                  placeholder="请输入手机号"></rh-input>
      </div>
      <div class="input">
        <label>密码</label>
        <rh-input type='password'
                  v-model="password"
                  placeholder="请输入密码"></rh-input>
      </div>
      <div class="input">
        <label>重复密码</label>
        <rh-input type='password'
                  v-model="repassword"
                  placeholder="请再次输入密码"></rh-input>
      </div>
      <div class="input">
        <rh-button type='f30'
                   @click="register">立即注册</rh-button>
      </div>

    </div>
    <!-- 尾部 -->
    <market-footer></market-footer>
  </div>
</template>

<script>
import MarketHeader from "@/components/common/MarketHeader"
import MarketFooter from "@/components/common/MarketFooter"
import RhInput from '@/components/basic/rh-input'
import RhButton from '@/components/basic/rh-button'
export default {
  components: {
    MarketHeader,
    MarketFooter,
    RhInput,
    RhButton
  },
  data () {
    return {
      username: '',
      password: '',
      userMail: '',
      userPhone: '',
      repassword: ''
    }
  },
  methods: {
    register () {
      if (this.password == this.repassword) {
        this.$http.post('http://localhost:3000/users/register', { username: this.username, password: this.password, userMail: this.userMail, userPhone: this.userPhone }).then(response => {
          if (response.data.status == 1) {
            alert(response.data.message)
          } else {
            alert(response.data.message);
            this.$router.go(-1);
          }
        })
      } else {
        alert('输入的密码不一致');
      }
    }
  }
}
</script>

<style lang="less" scoped>
.container {
  margin: 100px auto;
  width: 400px;
  height: 400px;
  border: 1px solid #ccc;

  .input {
    margin-top: 22px;
  }
  .rh-input {
    margin-left: 80px;
    width: 300px;
  }
  .rh-button {
    width: 300px;
  }
  .input > .rh-button:nth-of-type(1) {
    margin-left: 80px;
  }
  label {
    width: 80px;
    height: 40px;
    text-align: right;
    vertical-align: middle;
    float: left;
    font-size: 14px;
    color: #606266;
    line-height: 40px;
    padding: 0 12px 0 0;
    box-sizing: border-box;
  }
}
</style>